In [1]:
!mamba install bs4==4.10.0 -y
!mamba install html5lib==1.1 -y
!pip install lxml==4.6.4
!pip install yfinance==0.1.67
!pip install nbformat==4.2.0
                  __    __    __    __
                 /  \  /  \  /  \  /  \
                /    \/    \/    \/    \
███████████████/  /██/  /██/  /██/  /████████████████████████
              /  / \   / \   / \   / \  \____
             /  /   \_/   \_/   \_/   \    o \__,
            / _/                       \_____/  `
            |/
        ███╗   ███╗ █████╗ ███╗   ███╗██████╗  █████╗
        ████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗
        ██╔████╔██║███████║██╔████╔██║██████╔╝███████║
        ██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║
        ██║ ╚═╝ ██║██║  ██║██║ ╚═╝ ██║██████╔╝██║  ██║
        ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝ ╚═╝  ╚═╝

        mamba (0.15.3) supported by @QuantStack

        GitHub:  https://github.com/mamba-org/mamba
        Twitter: https://twitter.com/QuantStack

█████████████████████████████████████████████████████████████


Looking for: ['bs4==4.10.0']

pkgs/main/linux-64       [<=>                 ] (00m:00s) 
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [<=>                 ] (00m:00s) 
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [=>                ] (00m:00s) 776 KB / ?? (2.48 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [=>                ] (00m:00s) 776 KB / ?? (2.48 MB/s)
pkgs/r/linux-64          [<=>                 ] (00m:00s) 
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [=>                ] (00m:00s) 776 KB / ?? (2.48 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [=>                ] (00m:00s) 776 KB / ?? (2.48 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [<=>                 ] (00m:00s) 
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [=>                ] (00m:00s) 776 KB / ?? (2.48 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [=>                ] (00m:00s) 768 KB / ?? (2.44 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [<=>                 ] (00m:00s) Finalizing...
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [=>                ] (00m:00s) 768 KB / ?? (2.44 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/noarch         [<=>                 ] (00m:00s) Done
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [=>                ] (00m:00s) 768 KB / ?? (2.44 MB/s)
pkgs/main/noarch         [====================] (00m:00s) Done
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [=>                ] (00m:00s) 768 KB / ?? (2.44 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [<=>                 ] (00m:00s) Finalizing...
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/r/noarch            [<=>                 ] (00m:00s) Done
pkgs/r/noarch            [====================] (00m:00s) Done
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/r/linux-64          [=>                ] (00m:00s) 772 KB / ?? (2.46 MB/s)
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/r/linux-64          [<=>                 ] (00m:00s) Finalizing...
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/r/linux-64          [<=>                 ] (00m:00s) Done
pkgs/r/linux-64          [====================] (00m:00s) Done
pkgs/main/linux-64       [=>                ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/linux-64       [<=>               ] (00m:00s) 732 KB / ?? (2.35 MB/s)
pkgs/main/linux-64       [ <=>                ] (00m:00s) 1 MB / ?? (2.84 MB/s)
pkgs/main/linux-64       [  <=>               ] (00m:00s) 1 MB / ?? (2.84 MB/s)
pkgs/main/linux-64       [  <=>               ] (00m:00s) 2 MB / ?? (3.74 MB/s)
pkgs/main/linux-64       [   <=>              ] (00m:00s) 2 MB / ?? (3.74 MB/s)
pkgs/main/linux-64       [   <=>              ] (00m:00s) 3 MB / ?? (4.00 MB/s)
pkgs/main/linux-64       [    <=>             ] (00m:00s) 3 MB / ?? (4.00 MB/s)
pkgs/main/linux-64       [    <=>             ] (00m:00s) 4 MB / ?? (4.22 MB/s)
pkgs/main/linux-64       [     <=>            ] (00m:00s) 4 MB / ?? (4.22 MB/s)
pkgs/main/linux-64       [     <=>            ] (00m:00s) 5 MB / ?? (4.39 MB/s)
pkgs/main/linux-64       [     <=>            ] (00m:00s) Finalizing...
pkgs/main/linux-64       [     <=>            ] (00m:00s) Done
pkgs/main/linux-64       [====================] (00m:00s) Done

Pinned packages:
  - python 3.7.*


Transaction

  Prefix: /home/jupyterlab/conda/envs/python

  Updating specs:

   - bs4==4.10.0
   - ca-certificates
   - certifi
   - openssl


  Package               Version  Build           Channel                  Size
────────────────────────────────────────────────────────────────────────────────
  Install:
────────────────────────────────────────────────────────────────────────────────

  + bs4                  4.10.0  hd3eb1b0_0      pkgs/main/noarch        10 KB

  Upgrade:
────────────────────────────────────────────────────────────────────────────────

  - ca-certificates   2022.9.24  ha878542_0      installed                    
  + ca-certificates  2023.01.10  h06a4308_0      pkgs/main/linux-64     120 KB
  - certifi           2022.9.24  pyhd8ed1ab_0    installed                    
  + certifi           2022.12.7  py37h06a4308_0  pkgs/main/linux-64     150 KB
  - openssl              1.1.1s  h0b41bf4_1      installed                    
  + openssl              1.1.1t  h7f8727e_0      pkgs/main/linux-64       4 MB

  Downgrade:
────────────────────────────────────────────────────────────────────────────────

  - beautifulsoup4       4.11.1  pyha770c72_0    installed                    
  + beautifulsoup4       4.10.0  pyh06a4308_0    pkgs/main/noarch        85 KB

  Summary:

  Install: 1 packages
  Upgrade: 3 packages
  Downgrade: 1 packages

  Total download: 4 MB

────────────────────────────────────────────────────────────────────────────────

Downloading  [>                                        ] (00m:00s)  125.08 KB/s
Extracting   [>                                                      ] (--:--) 
Finished bs4                                  (00m:00s)              10 KB    125 KB/s
Downloading  [>                                        ] (00m:00s)  125.08 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [>                                        ] (00m:00s)  125.08 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [>                                        ] (00m:00s)  125.08 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [=>                                       ] (00m:00s)    1.88 MB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [==>                                      ] (00m:00s)    2.81 MB/s
Extracting   [>                                                      ] (--:--) 
Finished certifi                              (00m:00s)             150 KB      2 MB/s
Downloading  [==>                                      ] (00m:00s)    2.81 MB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [==>                                      ] (00m:00s)    2.81 MB/s
Extracting   [>                                                      ] (--:--) 
Finished beautifulsoup4                       (00m:00s)              85 KB    991 KB/s
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [========>                                ] (00m:00s)        1 / 5
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [========>                                ] (00m:00s)        1 / 5
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [========>                                ] (00m:00s)        1 / 5
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [========>                                ] (00m:00s)        1 / 5
Finished ca-certificates                      (00m:00s)             120 KB      1 MB/s
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [========>                                ] (00m:00s)        1 / 5
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [========>                                ] (00m:00s)        1 / 5
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [================>                        ] (00m:00s)        2 / 5
Downloading  [===>                                     ] (00m:00s)    3.95 MB/s
Extracting   [================>                        ] (00m:00s)        2 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [================>                        ] (00m:00s)        2 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [========================>                ] (00m:00s)        3 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [========================>                ] (00m:00s)        3 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [================================>        ] (00m:00s)        4 / 5
Finished openssl                              (00m:00s)               4 MB     27 MB/s
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [================================>        ] (00m:00s)        4 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [================================>        ] (00m:00s)        4 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [================================>        ] (00m:00s)        4 / 5
Downloading  [=========================================] (00m:00s)   29.03 MB/s
Extracting   [=========================================] (00m:00s)        5 / 5
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

                  __    __    __    __
                 /  \  /  \  /  \  /  \
                /    \/    \/    \/    \
███████████████/  /██/  /██/  /██/  /████████████████████████
              /  / \   / \   / \   / \  \____
             /  /   \_/   \_/   \_/   \    o \__,
            / _/                       \_____/  `
            |/
        ███╗   ███╗ █████╗ ███╗   ███╗██████╗  █████╗
        ████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗
        ██╔████╔██║███████║██╔████╔██║██████╔╝███████║
        ██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║
        ██║ ╚═╝ ██║██║  ██║██║ ╚═╝ ██║██████╔╝██║  ██║
        ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝ ╚═╝  ╚═╝

        mamba (0.15.3) supported by @QuantStack

        GitHub:  https://github.com/mamba-org/mamba
        Twitter: https://twitter.com/QuantStack

█████████████████████████████████████████████████████████████


Looking for: ['html5lib==1.1']

pkgs/main/linux-64       Using cache
pkgs/main/noarch         Using cache
pkgs/r/linux-64          Using cache
pkgs/r/noarch            Using cache

Pinned packages:
  - python 3.7.*


Transaction

  Prefix: /home/jupyterlab/conda/envs/python

  Updating specs:

   - html5lib==1.1
   - ca-certificates
   - certifi
   - openssl


  Package         Version  Build         Channel                 Size
───────────────────────────────────────────────────────────────────────
  Install:
───────────────────────────────────────────────────────────────────────

  + html5lib          1.1  pyhd3eb1b0_0  pkgs/main/noarch       91 KB
  + webencodings    0.5.1  py37_1        pkgs/main/linux-64     19 KB

  Summary:

  Install: 2 packages

  Total download: 110 KB

───────────────────────────────────────────────────────────────────────

Downloading  [======>                                  ] (00m:00s)  142.50 KB/s
Extracting   [>                                                      ] (--:--) 
Finished webencodings                         (00m:00s)              19 KB    142 KB/s
Downloading  [======>                                  ] (00m:00s)  142.50 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [======>                                  ] (00m:00s)  142.50 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [======>                                  ] (00m:00s)  142.50 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [=========================================] (00m:00s)  785.12 KB/s
Extracting   [>                                                      ] (--:--) 
Finished html5lib                             (00m:00s)              91 KB    647 KB/s
Downloading  [=========================================] (00m:00s)  785.12 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [=========================================] (00m:00s)  785.12 KB/s
Extracting   [>                                                      ] (--:--) 
Downloading  [=========================================] (00m:00s)  785.12 KB/s
Extracting   [====================>                    ] (00m:00s)        1 / 2
Downloading  [=========================================] (00m:00s)  785.12 KB/s
Extracting   [====================>                    ] (00m:00s)        1 / 2
Downloading  [=========================================] (00m:00s)  785.12 KB/s
Extracting   [=========================================] (00m:00s)        2 / 2
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Collecting lxml==4.6.4
  Downloading lxml-4.6.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.3/6.3 MB 66.2 MB/s eta 0:00:00:00:0100:01
Installing collected packages: lxml
  Attempting uninstall: lxml
    Found existing installation: lxml 4.9.1
    Uninstalling lxml-4.9.1:
      Successfully uninstalled lxml-4.9.1
Successfully installed lxml-4.6.4
Collecting yfinance==0.1.67
  Downloading yfinance-0.1.67-py2.py3-none-any.whl (25 kB)
Requirement already satisfied: pandas>=0.24 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (1.3.5)
Requirement already satisfied: requests>=2.20 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (2.28.1)
Requirement already satisfied: lxml>=4.5.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (4.6.4)
Collecting multitasking>=0.0.7
  Downloading multitasking-0.0.11-py3-none-any.whl (8.5 kB)
Requirement already satisfied: numpy>=1.15 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (1.21.6)
Requirement already satisfied: python-dateutil>=2.7.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas>=0.24->yfinance==0.1.67) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas>=0.24->yfinance==0.1.67) (2022.6)
Requirement already satisfied: charset-normalizer<3,>=2 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (2.1.1)
Requirement already satisfied: certifi>=2017.4.17 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (2022.12.7)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (1.26.13)
Requirement already satisfied: idna<4,>=2.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (3.4)
Requirement already satisfied: six>=1.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas>=0.24->yfinance==0.1.67) (1.16.0)
Installing collected packages: multitasking, yfinance
Successfully installed multitasking-0.0.11 yfinance-0.1.67
Collecting nbformat==4.2.0
  Downloading nbformat-4.2.0-py2.py3-none-any.whl (153 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 153.3/153.3 kB 19.2 MB/s eta 0:00:00
Requirement already satisfied: jupyter-core in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from nbformat==4.2.0) (4.12.0)
Requirement already satisfied: traitlets>=4.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from nbformat==4.2.0) (5.6.0)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from nbformat==4.2.0) (4.17.3)
Requirement already satisfied: ipython-genutils in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from nbformat==4.2.0) (0.2.0)
Requirement already satisfied: importlib-resources>=1.4.0 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (5.10.1)
Requirement already satisfied: attrs>=17.4.0 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (22.1.0)
Requirement already satisfied: typing-extensions in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (4.4.0)
Requirement already satisfied: pkgutil-resolve-name>=1.3.10 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (1.3.10)
Requirement already satisfied: importlib-metadata in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (4.11.4)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (0.19.2)
Requirement already satisfied: zipp>=3.1.0 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from importlib-resources>=1.4.0->jsonschema!=2.5.0,>=2.4->nbformat==4.2.0) (3.11.0)
Installing collected packages: nbformat
  Attempting uninstall: nbformat
    Found existing installation: nbformat 5.7.0
    Uninstalling nbformat-5.7.0:
      Successfully uninstalled nbformat-5.7.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
nbconvert 7.2.6 requires nbformat>=5.1, but you have nbformat 4.2.0 which is incompatible.
nbclient 0.7.2 requires nbformat>=5.1, but you have nbformat 4.2.0 which is incompatible.
jupyter-server 1.23.3 requires nbformat>=5.2.0, but you have nbformat 4.2.0 which is incompatible.
Successfully installed nbformat-4.2.0
In [2]:
import pandas as pd
import requests
from bs4 import BeautifulSoup
import yfinance as yf
import plotly.graph_objects as go
from plotly.subplots import make_subplots
In [3]:
def make_graph(stock_data, revenue_data, stock):
    fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("Historical Share Price", "Historical Revenue"), vertical_spacing = .3)
    stock_data_specific = stock_data[stock_data.Date <= '2021--06-14']
    revenue_data_specific = revenue_data[revenue_data.Date <= '2021-04-30']
    fig.add_trace(go.Scatter(x=pd.to_datetime(stock_data_specific.Date, infer_datetime_format=True), y=stock_data_specific.Close.astype("float"), name="Share Price"), row=1, col=1)
    fig.add_trace(go.Scatter(x=pd.to_datetime(revenue_data_specific.Date, infer_datetime_format=True), y=revenue_data_specific.Revenue.astype("float"), name="Revenue"), row=2, col=1)
    fig.update_xaxes(title_text="Date", row=1, col=1)
    fig.update_xaxes(title_text="Date", row=2, col=1)
    fig.update_yaxes(title_text="Price ($US)", row=1, col=1)
    fig.update_yaxes(title_text="Revenue ($US Millions)", row=2, col=1)
    fig.update_layout(showlegend=False,
    height=900,
    title=stock,
    xaxis_rangeslider_visible=True)
    fig.show()
In [4]:
tsla = yf.Ticker("TSLA")
In [5]:
tsla_data = tsla.history(period="max")
In [6]:
tsla_data.reset_index(inplace=True)
tsla_data.head()
Out[6]:
Date Open High Low Close Volume Dividends Stock Splits
0 2010-06-29 1.266667 1.666667 1.169333 1.592667 281494500 0 0.0
1 2010-06-30 1.719333 2.028000 1.553333 1.588667 257806500 0 0.0
2 2010-07-01 1.666667 1.728000 1.351333 1.464000 123282000 0 0.0
3 2010-07-02 1.533333 1.540000 1.247333 1.280000 77097000 0 0.0
4 2010-07-06 1.333333 1.333333 1.055333 1.074000 103003500 0 0.0
In [33]:
url = "https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/revenue.htm"

html_data = requests.get(url).text
In [34]:
soup = BeautifulSoup(html_data, 'html5lib')
In [39]:
tesla_revenue = pd.DataFrame(columns = ["Date","Revenue"])

for table in soup.find_all('table'):
    if table.find('th').getText().startswith("Tesla Quarterly Revenue"):
        for row in table.find("tbody").find_all("tr"):
            col = row.find_all("td")
            if len(col) != 2: continue
            Date = col[0].text
            Revenue = col[1].text.replace("$","").replace(",","")
               
            tesla_revenue = tesla_revenue.append({"Date":Date, "Revenue":Revenue}, ignore_index=True)
In [41]:
tesla_revenue.dropna(axis=0, how='all', subset=['Revenue']) #drop NaN values
tesla_revenue = tesla_revenue[tesla_revenue['Revenue'] != ""]
In [42]:
tesla_revenue.tail(5)
Out[42]:
Date Revenue
48 2010-09-30 31
49 2010-06-30 28
50 2010-03-31 21
52 2009-09-30 46
53 2009-06-30 27
In [43]:
gme = yf.Ticker('GME')
In [44]:
gme_data = gme.history(period='max')
In [45]:
gme_data.reset_index(inplace=True)
gme_data.head(5)
Out[45]:
Date Open High Low Close Volume Dividends Stock Splits
0 2002-02-13 1.620129 1.693350 1.603296 1.691667 76216000 0.0 0.0
1 2002-02-14 1.712707 1.716074 1.670626 1.683250 11021600 0.0 0.0
2 2002-02-15 1.683250 1.687458 1.658002 1.674834 8389600 0.0 0.0
3 2002-02-19 1.666418 1.666418 1.578047 1.607504 7410400 0.0 0.0
4 2002-02-20 1.615921 1.662210 1.603296 1.662210 6892800 0.0 0.0
In [46]:
url = "https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/stock.html"
html_data = requests.get(url).text
In [47]:
soup = BeautifulSoup(html_data, "html5lib")
In [48]:
gme_revenue = pd.DataFrame(columns = ["Date","Revenue"])

for table in soup.find_all('table'):
    if table.find('th').getText().startswith("GameStop Quarterly Revenue"):
        for row in table.find("tbody").find_all("tr"):
            col = row.find_all("td")
            if len(col) != 2: continue
            Date = col[0].text
            Revenue = col[1].text.replace("$","").replace(",","")
               
            gme_revenue = gme_revenue.append({"Date":Date, "Revenue":Revenue}, ignore_index=True)
In [49]:
gme_revenue.tail(5)
Out[49]:
Date Revenue
57 2006-01-31 1667
58 2005-10-31 534
59 2005-07-31 416
60 2005-04-30 475
61 2005-01-31 709
In [51]:
tesla = yf.Ticker('TSLA')
In [52]:
tesla_data = tesla.history(period="max")
tesla_data.reset_index(inplace=True)
In [53]:
make_graph(tesla_data, tesla_revenue, 'Tesla')
In [54]:
make_graph(gme_data, gme_revenue, 'GameStop')
In [ ]: